<?php
namespace addons\member\controllers;
use addons\member\models\Member;
use controllers\HomeBase;
use system\Route\Request;

class api extends HomeBase {
	protected $model = '';
	protected $allowPlatform = [1 , 2];

	/**
	 * 登陆接口
	 * @param Request $request
	 * @author Colin <amcolin@126.com>
	 * @date 2022-01-26 上午10:55
	 * @return bool
	 */
	public function login(Request $request){
		$platform = $request->post('platform');
		$username = $request->post('username');
		$pass = $request->post('password');
		if (!in_array($platform , $this->allowPlatform)){
			return error('platform不正确');
		}
		if (!$username || !$pass){
			return error('账号或密码不能为空');
		}
		$model = new Member();
		$find = $model->where(['account' => $username , 'state' => 1 , 'platform' => $platform])->find();
		if (!$find){
			return error('用户名或密码不正确');
		}
		switch ($find['platform']){
			case 1 :
				if ($find['pass'] != $model->genderPassword($username , $pass)){
					return error('用户名或密码不正确');
				}
				break;
		}
		session('login_uid' , $find['id']);
		return success('登录成功');
	}

	/**
	 * 注册
	 * @param Request $request
	 * @author Colin <amcolin@126.com>
	 * @date 2022-01-26 上午11:15
	 */
	public function register(Request $request){
		var_dump($request);
	}

}